package org.example.demo.service.userService.impl;

import org.example.demo.dto.ProductShowParam;
import org.example.demo.service.userService.ShopService;
import org.example.mbg.mapper.ProductMapper;
import org.example.mbg.mapper.ShopMapper;
import org.example.mbg.model.ProductExample;
import org.example.mbg.model.Shop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private ShopMapper shopMapper;

    @Override
    public Shop show(Long id) {
        return shopMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ProductShowParam> listProducts(Long id) {
        ProductExample productExample = new ProductExample();
        productExample.createCriteria().andShopIdEqualTo(id);
        return productMapper.selectByExample(productExample).stream().map(e -> {
            ProductShowParam productShowParam = new ProductShowParam();
            productShowParam.setId(e.getId());
            productShowParam.setPage(e.getPage());
            productShowParam.setTitle(e.getName());
            productShowParam.setImg(e.getPic());
            productShowParam.setSales(e.getSale());
            productShowParam.setPrice(e.getPrice());
            productShowParam.setDiscount(e.getDiscount());
            productShowParam.setServices(e.getServices());
            productShowParam.setCfav(e.getCfav());
            return productShowParam;
        }).collect(Collectors.toList());
    }
}
